-- NewApplyListPanel

local NewApplyListRender = import(".renders.NewApplyListRender")

local ClassRef = app.mvc.createPanelClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewApplyListNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._isInCrossMatch = false

	self._ui["Panel/Panel_bom/selected_btn"]:addClickEventListener(function()
			if self._isInCrossMatch then
				display.pushToast(L("CrossServerTips16"))
				return
			end

			local oldStatus = self._ui["Panel/Panel_bom/selected_btn"]:isBright() -- false表示自动同意申请
			self._ui["Panel/Panel_bom/selected_btn"]:setBright( not oldStatus )
			executeFunc(self._onPanelHandler, "NewApplyListPanel_changeAutoApprove", oldStatus)
		end)

	self._list = self._ui["Panel/ListView"]
	self._list:removeAllItems()
	self._list.createRender = function (list, idx)
		local items = list:getItems()
		local render = items[idx]
		if nil == render then
			render = NewApplyListRender.create()
			list:pushBackCustomItem(render)
		end
		render:setVisible(true)
		return render
	end
end

-- 刷新"自动同意申请"按钮状态
function ClassRef:refreshAutoApprove(isAutoApprove, isInCrossMatch) -- true - 表示需要申请（即非自动）
	self._ui["Panel/Panel_bom/selected_btn"]:setBright( not isAutoApprove )
	self._isInCrossMatch = isInCrossMatch
end

function ClassRef:registerOnOperate( cb )
	self._onPanelHandler = cb
end

function ClassRef:getListView()
	return self._list
end

function ClassRef:remove()
end

return ClassRef
